// pages/my/my.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    user:{},
    id:1
  },
  onLoad: function (options) {
    try {
      //JSON.parse()里只能是字符串，将值存到storage之后不会改变值得类型，此时值就不是字符串
      let userInfo = typeof wx.getStorageSync('userInfo')==='string'? JSON.parse(wx.getStorageSync('userInfo')):wx.getStorageSync('userInfo');
      let user = typeof wx.getStorageSync('user')==='string'? JSON.parse(wx.getStorageSync('user')):wx.getStorageSync('user');
      this.setData({
        userInfo,
        user
      });
      console.log(userInfo);
    } catch (error) {
      wx.navigateTo({
        url: '../login/login',
      })
    }
  },
  onShow: function () {},
  changeImg() {
    let {
      userInfo
    } = this.data;
    console.log(userInfo);
    wx.chooseImage({
      count: 1,
      success: (result) => {
        console.log(result.tempFilePaths[0]);
        userInfo.avatarUrl = result.tempFilePaths[0];
        this.setData({
          userInfo
        });
        wx.setStorageSync('userInfo', userInfo);

      }
    })
  },
  editName(){
    wx.navigateTo({
      url: '../selfManage/selfManage',
    })
  }

})